<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="resposta" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{respostaHome.managed ? 'Editar' : 'Cadastro de'} Resposta</f:facet>

			<s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/RespostaList.xhtml"
		                    id="list"
		           propagation="none">
		            <h:graphicImage url="/img/list.png"/>
		            #{' '}
		            <h:outputLabel value="Listagem"/>
		        </s:link>
		    </s:div>


            <s:decorate id="cliquesField" template="/layout/display.xhtml">
                <ui:define name="label">Enunciado</ui:define>
                <h:outputText id="cliques" value="#{respostaHome.instance.questao.questao}"/>
            </s:decorate>


            <s:decorate id="corretaField" template="/layout/edit.xhtml">
                <ui:define name="label">Correta</ui:define>
                <h:selectBooleanCheckbox id="correta"
                                      value="#{respostaHome.instance.correta}"/>
            </s:decorate>



            <s:decorate id="respostaField" template="/layout/edit.xhtml">
                <ui:define name="label">Resposta</ui:define>
                <h:inputTextarea id="resposta"
                               cols="80"
                               rows="3"
                              value="#{respostaHome.instance.resposta}"
                           required="true"/>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                campos obrigatórios
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Salvar"
                         action="#{respostaHome.persist}"
                       disabled="#{!respostaHome.wired}"
                       rendered="#{!respostaHome.managed}"/>

            <h:commandButton id="update"
                          value="Salvar"
                         action="#{respostaHome.update}"
                       rendered="#{respostaHome.managed}"/>

            <h:commandButton id="delete"
                          value="Deletar"
                         action="#{respostaHome.remove}"
                      immediate="true"
                       rendered="#{respostaHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancelar"
             propagation="end"
                    view="/resources/Resposta.xhtml"
                rendered="#{respostaHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancelar"
             propagation="end"
                    view="/resources/#{empty respostaFrom ? 'RespostaList' : respostaFrom}.xhtml"
                rendered="#{!respostaHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Questão">
    <div class="association" id="questaoParent">

        <h:outputText value="Não existe Questão atrelada a esta Resposta."
                   rendered="#{respostaHome.instance.questao == null}"/>

        <rich:dataTable var="_questao"
                   value="#{respostaHome.instance.questao}"
                rendered="#{respostaHome.instance.questao != null}"
              rowClasses="odd,even"
                      id="questaoTable">
            <h:column>
                <f:facet name="header">Enunciado</f:facet>
                <h:outputText value="#{_questao.questao}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Acertos</f:facet>
                <h:outputText value="#{_questao.acertos}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Erros</f:facet>
                <h:outputText value="#{_questao.erros}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Tipo da Questão</f:facet>
                <h:outputText value="#{_questao.tipoQuestao}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{respostaHome.instance.questao != null ? 'changeParent' : 'selectParent'}" value="#{respostaHome.instance.questao != null ? 'Trocar' : 'Selecionar'} Questão"
                       view="/resources/QuestaoList.xhtml">
                <f:param name="from" value="RespostaEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
